#include <bits/stdc++.h>
using namespace std ;

const int maxn = 1e5 + 5 ;
int n, m, a[maxn], ax[maxn], aa[5] ;
int c[maxn] ;
int rg[31][maxn] ;
string str[maxn] ;

inline void solve() {
	for (int i = 1; i <= 4; ++ i) cin >> aa[i] ;
	for (int i = 1; i <= n; ++ i) a[i] = ax[i] xor aa[i % 4],cout << a[i] << ' ' ;
	for (int i = 1; i <= n; ++ i)  ;
	cout << endl ;
}

int main() {

    // freopen("arena.in", "r", stdin) ;
    // freopen("arena.out", "w", stdout) ;
    
    ios::sync_with_stdio(false) ;
    cin >> n >> m ;
    for (int i = 1; i <= n; ++ i) cin >> ax[i] ;
    for (int i = 1; i <= m; ++ i) cin >> c[i] ;
    
    int K = 1 ;
    while (pow(2, K) < n) ++ K ;
    
    for (int i = 1; i <= K; ++ i)
		for (int j = 1; j <= pow(2, K - i); ++ j)
			cin >> str[i] ;
			
	int T ; cin >> T ;
	while (T--) solve() ;
    
    return 0 ;
}

/*
5 5
0 0 0 0 0
5 4 1 2 3
1001
10
1
4
2 1 0 0
1 2 1 0
0 2 3 1
2 2 0 1
*/
